package com.rj.core.validation;

import com.rj.util.VerifyUtils;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.hibernate.validator.constraints.Length;


/**
 * @author YFX_RANLUBO
 */
public class LengthValidator implements ConstraintValidator<Length, String> {
    protected int min;
    protected int max;

    public LengthValidator() {
    }

    @Override
    public void initialize(Length constraintAnnotation) {

        min = constraintAnnotation.min();
        max = constraintAnnotation.max();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        return VerifyUtils.between(false, value.length(), min, max);
    }


}